Week6

Version/Date: Oct 24, 2017

Exercise

PREDICT_400-DL_SEC56 Week6 Discussion

File(s)

Simple Convergence Graphs using Plotly.ipynb

Instructions

In your own words, explain the difference between average rate of change and instantaneous rate of change. Do they have anything in common? How is average rate of change used in determining instantaneous rate of change? Share with us a specific application of average rate of change and a specific application of instantaneous rate of change. Ideally choose something you’ve encountered in your work or perhaps something that interests you.

Description

Why Plotly? Well, it's an interesting alternative to matplotlib pyplot that I've been meaning to try.

Explanation & Example

In my own simplistic view, the only difference between average rate of change and instantaneous rate of change is simply the length of the interval the over which the observation is made.

I took an example involving rate of change in descent. When the weather starts getting colder, nothing interests me more than looking forward to my next ski trip. When it starts snowing I want to be outside skiing down the mountain.

Let's say I take a given ski run down a mountain and want to know what my rate of descent will be through a given portion of the run. If I assume my speed down the a section of the hill will be directly proportional to the slope of run through that same section, then I can predict which part of the run will be my favorite based on which portion is the fastest... childish perhaps but let's go with it. Also to keep this example simple and relevant, I'll ignore other variables like changing surface conditions, obstacles, or the fact that my speed at any given section is dependent upon my speed entering that section of the run. I've made up a completely fictious run profile below to illustrate.

As you see from the various slopes, the interval span determines the slope and as the interval span decreases, the it gets closer to resembling the slope at a single point on the hill. Thus the instanteous rate of change at a given point will be determined by the average rate of change for the two points on either side of that instant as the span between those two points diminishes to zero.

So if I want to know how quickly I'm moving down the, um, slope (pun absolutely intended) at a given point then I simply need to look at the average rate of descent across two points of equal distance fromme up the hill and down the hill from my exact location. The more points I define on the continuous ski slope the easier it is to approximate the instanteous rate of descent at a given point.


In [49]:
# pip install plotly first if you havent already done so. 
# This cell will produce an error on the imports if not installed.
import plotly.plotly
from plotly.graph_objs import Scatter, Layout

In [54]:
# simple offline plot for slope - note the iplot method for jupyter as opposed to the normal plot.
plotly.offline.init_notebook_mode(connected=True)

# Made up scatter plot of the entire mountain ski run profile
full_run = Scatter(x=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], 
                           y=[5, 4.9, 4.2, 4.1, 4, 2.8, 2.6, 2.6, 2.5, 1.8, 1.2, 1], name='entire run', 
                           line=dict(color='#bc42f4'))

top_half_name_slope = 'top half - slope is ' + str(round((2.8-5)/(6-1),2))
top_half = Scatter(x=[1, 6], y=[5, 2.8], name=top_half_name_slope, line=dict(color='#41c1f4'))
bottom_half_name_slope = 'bottom half - slope is ' + str(round((1-2.8)/(12-6),2))
bottom_half = Scatter(x=[6,12], y=[2.8,1], name=bottom_half_name_slope, line=dict(color='#41f1f4'))

top_third_name_slope = 'top third - slope is ' + str(round((4.1-5)/(4-1),2))
top_third = Scatter(x=[1, 4], y=[5, 4.1], name=top_third_name_slope, line=dict(color='#41f49d'))
middle_third_name_slope = 'middle third - slope is ' + str(round((2.6-4.1)/(8-4),2))
middle_third = Scatter(x=[4,8], y=[4.1,2.6], name=middle_third_name_slope, line=dict(color='#4ff441'))
bottom_third_name_slope = 'bottom third - slope is ' + str(round((1-2.6)/(12-8),2))
bottom_third = Scatter(x=[8,12], y=[2.6,1], name=bottom_third_name_slope, line=dict(color='#b5f441'))

top_fourth_name_slope = 'top fourth - slope is ' + str(round((4.2-5)/(3-1),2))
top_fourth = Scatter(x=[1, 3], y=[5, 4.2], name=top_fourth_name_slope, line=dict(color='#f4cd41'))
midhigh_fourth_name_slope = 'midhigh fourth - slope is ' + str(round((2.8-4.2)/(6-3),2))
midhigh_fourth = Scatter(x=[3, 6], y=[4.2, 2.8], name=midhigh_fourth_name_slope, line=dict(color='#f4ac41'))
midlow_fourth_name_slope = 'midlow fourth - slope is ' + str(round((2.5-2.8)/(9-6),2))
midlow_fourth = Scatter(x=[6, 9], y=[2.8, 2.5], name=midlow_fourth_name_slope, line=dict(color='#f48241'))
bottom_fourth_name_slope = 'bottom fourth - slope is ' + str(round((1-2.5)/(12-9),2))
bottom_fourth = Scatter(x=[9, 12], y=[2.5, 1], name=bottom_fourth_name_slope, line=dict(color='#f44641'))

# slope between the second point and the sixth point
slope_part1_label = 'slope pt1 - slope is ' + str(round((4.2-5)/(3-1),2))
slope_part1 = Scatter(x=[2, 6], y=[4.9, 2.8], name=slope_part1_label, line=dict(color='#41f49d'))
# slope between the third point and the fifth point
slope_part2_label = 'slope pt2 - slope is ' + str(round((4-4.2)/(5-3),2))
slope_part2 = Scatter(x=[3, 5], y=[4.2, 4], name=slope_part2_label, line=dict(color='#f44641'))

#slope_part3_label = 'slope pt3 - slope is ' + str(round((4.1-4.2)/(4-3),2))
#slope_part3 = Scatter(x=[3, 4], y=[4.2, 4.1], name=slope_part3_label, line=dict(color='#f48241'))
#slope_part4_label = 'slope pt4 - slope is ' + str(round((4-4.1)/(5-4),2))
#slope_part4 = Scatter(x=[4, 5], y=[4.1, 4], name=slope_part4_label, line=dict(color='#f44641'))

plotly.offline.iplot({
    "data": [full_run, top_half, slope_part1, slope_part2],
    "layout": Layout(title="mountain run profile")
})

print('From this graph we would assume the rate of descent at point (4,4.1) is ' + 
      str(round((4-4.2)/(5-3),2)))
print('As we converge on a given point, the average rate approaches the instanteous rate.')


From this graph we would assume the rate of descent at point (4,4.1) is -0.1
As we converge on a given point, the average rate approaches the instanteous rate.

This is a simple example and so it is easy to see the relationship between average and instanteous rate of change. However, if we wanted to find teh instanteous rate of change at the point (5,4) we would need to know the exact points on the graph as we get closer and closer to the that point from either side. Alternatively, if we have a function that describes the points plotted for all real numbers, then we can find the derivative at that point and it will tell us exactly how quickly I'm descending the mountain at that exact moment. Taking an average over two points may not be accurate if the distance between those two observation points is high. This would not account from variations in rate of change between those two points.